package com.base.commonlib.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Environment;


/**
 * Created by codeest on 2016/8/4.
 */
public class SystemUtil {


    /**
     * 获取versionCode
     * @param context
     * @return
     */
    public static int getVersionCode(Context context) {
        PackageManager manager = context.getPackageManager();
        PackageInfo info;
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
            return info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return 0;
    }
    public static String packageName(Context context) {
        PackageManager manager = context.getPackageManager();
        String name = null;
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            name = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            name = "";
        }

        return name;
    }


    private static boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);

    public static String getAppDir() {

        if (hasSDCard) { // SD卡根目录的hello.text
//            String path = Environment.getExternalStorageDirectory() + "/Greenb/apk/";
//            File file = new File(path);
//            if (!file.exists()){
//                file.mkdirs();
//            }
            return  Environment.getExternalStorageDirectory() + "/crpuct/";
        } else {  // 系统下载缓存根目录的hello.text
//            String path = Environment.getDownloadCacheDirectory() + "/Green/apk/";
//            File file = new File(path);
//            if (!file.exists()){
//                file.mkdirs();
//            }
            return Environment.getDownloadCacheDirectory()+"/crpuct/";
        }
    }
}
